<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of find_nearest_pt</title>
  <meta name="keywords" content="find_nearest_pt">
  <meta name="description" content="Find nearest point in Mesh structure to (x,y)">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">fvcom_prepro</a> &gt; find_nearest_pt.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for fvcom_prepro&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>find_nearest_pt
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>Find nearest point in Mesh structure to (x,y)</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [Point,Distance] = find_nearest_pt(xloc,yloc,Mobj) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> Find nearest point in Mesh structure to (x,y) 

 function [Point,Distance] = find_nearest_pt(xloc,yloc,Mobj) 

 DESCRIPTION:
    Find nearest point to (xloc,yloc) in the domain of Mobj
    using native coordinates of Mobj

 INPUT: 
   xloc   = x location of point (in native Mobj coordinates)
   yloc   = y location of point (in native Mobj coordinates)
   Mobj   = Mesh object
           
 OUTPUT:
   Point = index of nearest vertex in the mesh
   Distance = Distance from x,y to Point in Mobj native coordinates

 EXAMPLE USAGE
    [Point,Distance] = find_nearest_point(50.1,100.2,Mobj)

 Author(s):  
    Geoff Cowles (University of Massachusetts Dartmouth)

 Revision history
   
==============================================================================</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="add_obc_nodes_graphic.html" class="code" title="function [Mobj]  = add_obc_nodes_screen(Mobj,ObcName,ObcType)">add_obc_nodes_graphic</a>	Add a set of obc nodes comprising a single obc boundary to Mesh structure</li><li><a href="add_river_nodes_graphic.html" class="code" title="function [Mobj]  = add_river_nodes(Mobj,RiverName)">add_river_nodes_graphic</a>	Add a set of river nodes comprising a single river to Mesh structure</li><li><a href="add_sponge_nodes.html" class="code" title="function [Mobj]  = add_sponge_nodes(Mobj,SpongeName,SpongeRadius,SpongeCoeff)">add_sponge_nodes</a>	Add a set of sponge nodes comprising a single sponge layer to Mesh structure</li></ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [Point,Distance] = find_nearest_pt(xloc,yloc,Mobj) </a>
0002 
0003 <span class="comment">% Find nearest point in Mesh structure to (x,y)</span>
0004 <span class="comment">%</span>
0005 <span class="comment">% function [Point,Distance] = find_nearest_pt(xloc,yloc,Mobj)</span>
0006 <span class="comment">%</span>
0007 <span class="comment">% DESCRIPTION:</span>
0008 <span class="comment">%    Find nearest point to (xloc,yloc) in the domain of Mobj</span>
0009 <span class="comment">%    using native coordinates of Mobj</span>
0010 <span class="comment">%</span>
0011 <span class="comment">% INPUT:</span>
0012 <span class="comment">%   xloc   = x location of point (in native Mobj coordinates)</span>
0013 <span class="comment">%   yloc   = y location of point (in native Mobj coordinates)</span>
0014 <span class="comment">%   Mobj   = Mesh object</span>
0015 <span class="comment">%</span>
0016 <span class="comment">% OUTPUT:</span>
0017 <span class="comment">%   Point = index of nearest vertex in the mesh</span>
0018 <span class="comment">%   Distance = Distance from x,y to Point in Mobj native coordinates</span>
0019 <span class="comment">%</span>
0020 <span class="comment">% EXAMPLE USAGE</span>
0021 <span class="comment">%    [Point,Distance] = find_nearest_point(50.1,100.2,Mobj)</span>
0022 <span class="comment">%</span>
0023 <span class="comment">% Author(s):</span>
0024 <span class="comment">%    Geoff Cowles (University of Massachusetts Dartmouth)</span>
0025 <span class="comment">%</span>
0026 <span class="comment">% Revision history</span>
0027 <span class="comment">%</span>
0028 <span class="comment">%==============================================================================</span>
0029 
0030 subname = <span class="string">'find_nearest_pt'</span>;
0031 <span class="comment">%fprintf('\n')</span>
0032 <span class="comment">%fprintf(['begin : ' subname '\n'])</span>
0033 
0034 <span class="comment">%------------------------------------------------------------------------------</span>
0035 <span class="comment">% Parse input arguments</span>
0036 <span class="comment">%------------------------------------------------------------------------------</span>
0037 <span class="keyword">if</span>(exist(<span class="string">'xloc'</span>)*exist(<span class="string">'yloc'</span>)*exist(<span class="string">'Mobj'</span>) == 0)
0038     error(<span class="string">'arguments to find_nearest_pt are missing'</span>)
0039 <span class="keyword">end</span>;
0040 
0041 <span class="comment">%------------------------------------------------------------------------------</span>
0042 <span class="comment">% Set native coordinates</span>
0043 <span class="comment">%------------------------------------------------------------------------------</span>
0044 <span class="keyword">if</span>(lower(Mobj.nativeCoords(1:3)) == <span class="string">'car'</span>)
0045     x = Mobj.x;
0046     y = Mobj.y;
0047 <span class="keyword">else</span>
0048     x = Mobj.lon;
0049     y = Mobj.lat;
0050 <span class="keyword">end</span>;
0051 
0052 <span class="comment">%------------------------------------------------------------------------------</span>
0053 <span class="comment">% Find the nearest point</span>
0054 <span class="comment">%------------------------------------------------------------------------------</span>
0055 radvec = sqrt( (xloc-x).^2 + (yloc-y).^2);
0056 [Distance,Point] = min(radvec);
0057 
0058 
0059 <span class="comment">%fprintf(['end   : ' subname '\n'])</span>
0060 
0061</pre></div>
<hr><address>Generated on Wed 02-Nov-2011 21:58:00 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>